<?php

header('Access-Control-Allow-Origin:*');  //支持全域名访问，不安全，部署后需要固定限制为客户端网址
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); //支持的http 动作
header('Access-Control-Allow-Headers:x-requested-with,content-type'); 
$conn=mysqli_connect("localhost","root","","fruit");
$conn->query("set names utf_8");
$type=$_POST["type"];
switch ($type){
    case "add":
        $name=$_POST["name"];
        $pwd=$_POST["pwd"];
        $phone=$_POST["phone"];
        $sql="INSERT INTO USER (name,pwd,phone) VALUE ('{$name}','{$pwd}','{$phone}')";
        $conn->query($sql);
        if(mysqli_affected_rows($conn)>0){
            echo '{"bol":true}';
        }else{
            echo '{"bol":false}';
        }
        break;
     case "checkzc":
        $name=$_POST["name"];
        $sql="SELECT * FROM user WHERE name='{$name}'";
        $conn->query($sql);
//        echo mysqli_affected_rows($conn);
        if(mysqli_affected_rows($conn)>0){
            echo '{"bol":true}';
        }else{
            echo '{"bol":false}';
        }
        break;
    case "check":
        $name=$_POST["name"];
        $pwd=$_POST["pwd"];
        $sql="SELECT * FROM user WHERE (name,pwd) =('{$name}','{$pwd}')";
        $conn->query($sql);
//        echo mysqli_affected_rows($conn);
        if(mysqli_affected_rows($conn)>0){
            echo '{"bol":true}';
        }else{
            echo '{"bol":false}';
        }


// //        echo mysqli_affected_rows($conn);
//         if(mysqli_affected_rows($conn)>0){
//             echo '{"bol":true}';
//         }else{
//             echo '{"bol":false}';
//         }
        break;
}
